package com.cryptoneedle.center.source.entity.enhance;


import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.center.source.entity.metadata.SourceColumn;
import com.cryptoneedle.center.source.entity.metadata.SourceTable;
import com.cryptoneedle.center.source.enums.DimensionOriginType;
import com.cryptoneedle.center.source.key.enhance.SourceEnhanceDimensionKey;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
 * <p>description: 源数据源-增强-维度 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-20
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = {"sourceTable", "sourceColumn"})
@ToString(callSuper = true, exclude = {"sourceTable", "sourceColumn"})
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "public", name = "source_enhance_dimension")
@IdClass(SourceEnhanceDimensionKey.class)
@Comment("源数据源-增强-维度")
public class SourceEnhanceDimension extends BaseEntity {
    
    @Id
    @Comment("源数据源-目录名称")
    private String sourceCatalogName;
    
    @Id
    @Comment("源数据源-数据库名称")
    private String sourceDatabaseName;
    
    @Id
    @Comment("源数据源-表名称")
    private String sourceTableName;
    
    @Id
    @Comment("源数据源-维度名称")
    private String sourceDimensionName;
    
    @Id
    @Comment("源数据源-列名称")
    private String sourceColumnName;
    
    @Comment("列排序")
    private Integer position;
    
    @Enumerated(EnumType.STRING)
    @Comment("源数据源-维度来源")
    private DimensionOriginType origin;
    
    @Comment("源数据源-启用列")
    private Boolean enabled;
    
    @Comment("源数据源-激活维度")
    private Boolean active;
    
    /**
     * 关联关系
     */
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
            @JoinColumn(name = "sourceCatalogName", referencedColumnName = "sourceCatalogName", insertable = false, updatable = false),
            @JoinColumn(name = "sourceDatabaseName", referencedColumnName = "sourceDatabaseName", insertable = false, updatable = false),
            @JoinColumn(name = "sourceTableName", referencedColumnName = "sourceTableName", insertable = false, updatable = false)
    })
    private SourceTable sourceTable;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
            @JoinColumn(name = "sourceCatalogName", referencedColumnName = "sourceCatalogName", insertable = false, updatable = false),
            @JoinColumn(name = "sourceDatabaseName", referencedColumnName = "sourceDatabaseName", insertable = false, updatable = false),
            @JoinColumn(name = "sourceTableName", referencedColumnName = "sourceTableName", insertable = false, updatable = false),
            @JoinColumn(name = "sourceColumnName", referencedColumnName = "sourceColumnName", insertable = false, updatable = false)
    })
    private SourceColumn sourceColumn;
}